#!/usr/bin/env python

import os
import subprocess
import socket
import sys
import time
from struct import *
import ssl

import paho.mqtt.client as mqtt

if sys.version < '2.7':
    print("WARNING: SSL/TLS not supported on Python 2.6")
    exit(0)

def on_connect(mqttc, obj, flags, rc):
    exit(1)

mqttc = mqtt.Client("08-ssl-fake-cacert")
mqttc.tls_set("../ssl/test-fake-root-ca.crt", "../ssl/client.crt", "../ssl/client.key")
mqttc.on_connect = on_connect

try:
    mqttc.connect("localhost", 1888)
except ssl.SSLError as msg:
    if msg.errno == 1 and "certificate verify failed" in msg.strerror:
        exit(0)
    else:
        exit(1)
else:
    exit(1)
